using System;

namespace WcfExtensions.ServiceModel.Channels
{
    internal static class WSCompression
    {
        #region Nested type: Algorithm

        public static class Algorithm
        {
            public const string deflate = "urn:wcfextensions:soap:compression:2007:09:deflate";
            public const string gzip = "urn:wcfextensions:soap:compression:2007:09:gzip";

            public static CompressionAlgorithm ConvertToAlgorithm(string algorithm)
            {
                switch (algorithm)
                {
                    case gzip:
                        return CompressionAlgorithm.GZip;
                    case deflate:
                        return CompressionAlgorithm.Deflate;
                    default:
                        throw new NotSupportedException("Compression mode " + algorithm + " is not supported");
                }
            }

            public static string ConvertToString(CompressionAlgorithm algorithm)
            {
                switch (algorithm)
                {
                    case CompressionAlgorithm.GZip:
                        return gzip;
                    case CompressionAlgorithm.Deflate:
                        return deflate;
                    default:
                        throw new NotSupportedException("Compression mode " + algorithm + " is not supported");
                }
            }
        }

        #endregion

        #region Nested type: Level

        public static class Level
        {
            public const string Fast = "Fast";
            public const string Maximum = "Maximum";
            public const string NoCompression = "None";
            public const string Normal = "Normal";

            public static CompressionLevel ConvertToLevel(string level)
            {
                switch (level)
                {
                    case Fast:
                        return CompressionLevel.Fast;
                    case Normal:
                        return CompressionLevel.Normal;
                    case Maximum:
                        return CompressionLevel.Maximum;
                    case NoCompression:
                        return CompressionLevel.NoCompression;
                    default:
                        throw new NotSupportedException(String.Format("Compression mode {0} is not supported", level));
                }
            }

            public static string ConvertToString(CompressionLevel level)
            {
                switch (level)
                {
                    case CompressionLevel.Fast:
                        return Fast;
                    case CompressionLevel.Normal:
                        return Normal;
                    case CompressionLevel.Maximum:
                        return Maximum;
                    case CompressionLevel.NoCompression:
                        return NoCompression;
                    default:
                        throw new NotSupportedException(String.Format("Compression mode {0} is not supported", level));
                }
            }
        }

        #endregion
    }
}